package reliability.ui;

import reliability.model.GraphModel;
import reliability.model.GraphModelEvent;
import reliability.model.GraphModelListener;

import javax.swing.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public abstract class InfoPanelComponent
    extends JPanel
    implements GraphModelListener, FocusListener

{
    protected GraphModel model;

    public InfoPanelComponent(GraphModel model)
    {
        super();
        this.model = model;
        model.addListener(this);
    }

    protected double getDoubleValue(Object object)
    {
        double doubleValue = 0;
        if ((object instanceof Double))
        {
            doubleValue = (Double) object;
        }
        else if (object instanceof Integer)
        {
            doubleValue = ((Integer) object).doubleValue();
        }
        else if (object instanceof Long)
        {
            doubleValue = ((Long) object).doubleValue();
        }
        else
        {
            throw new RuntimeException("Failed to get double value");
        }
        return doubleValue;
    }

    public void focusGained(FocusEvent focusEvent){}

    public void focusLost(FocusEvent focusEvent) {}

    public abstract void graphModelChanged(GraphModelEvent event);
}
